﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace KhoBanHang
{
    public partial class TongHopBanHang : Form
    {
        public TongHopBanHang()
        {
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void TongHopBanHang_Load(object sender, EventArgs e)
        {   
            dateTimePicker1.CustomFormat="dd/MM/yyyy";
            dateTimePicker2.CustomFormat="dd/MM/yyyy";
            
        }



        private void btnXem_Click(object sender, EventArgs e)
        {

            if (rbtnmatHang.Checked == true)
            {
                DateTime? tungay = dateTimePicker1.Value;
                DateTime? denngay = dateTimePicker2.Value;

                QLKD_KhoaLuanDataSet.TongHopBanHang_MatHang_SoLuongBanDataTable table = new QLKD_KhoaLuanDataSet.TongHopBanHang_MatHang_SoLuongBanDataTable();
                QLKD_KhoaLuanDataSetTableAdapters.TongHopBanHang_MatHang_SoLuongBanTableAdapter ada = new KhoBanHang.QLKD_KhoaLuanDataSetTableAdapters.TongHopBanHang_MatHang_SoLuongBanTableAdapter();
                ada.Fill(table, tungay, denngay);
                ReportDataSource rds = new ReportDataSource("QLKD_KhoaLuanDataSet_TongHopBanHang_MatHang_SoLuongBan", table);
                reportViewer1.LocalReport.DataSources.Clear();
                reportViewer1.LocalReport.DataSources.Add(rds);

                List<ReportParameter> listBien = new List<ReportParameter>();
                ReportParameter bien = new ReportParameter("tungay", dateTimePicker1.Value.ToString("dd/MM/yyyy"));
                listBien.Add(bien);
                ReportParameter bien2 = new ReportParameter("denngay", dateTimePicker2.Value.ToString("dd/MM/yyyy"));
                listBien.Add(bien2);

                reportViewer1.LocalReport.SetParameters(listBien);
                this.reportViewer1.RefreshReport();
                reportViewer1.Visible = true;

                reportViewerNV.Visible = false;
                reportViewerKH.Visible = false;

            }
            else if (rbtnKH.Checked == true)
            {
                DateTime tungay2 = dateTimePicker1.Value;
                DateTime denngay2 = dateTimePicker2.Value;

                QLKD_KhoaLuanDataSet.KhachHangDataTable dt_KH = new QLKD_KhoaLuanDataSet.KhachHangDataTable();
                QLKD_KhoaLuanDataSetTableAdapters.KhachHangTableAdapter ada_KH = new KhoBanHang.QLKD_KhoaLuanDataSetTableAdapters.KhachHangTableAdapter();
                ada_KH.Fill(dt_KH, tungay2, denngay2);
                ReportDataSource rds = new ReportDataSource("QLKD_KhoaLuanDataSet_KhachHang", dt_KH);
                reportViewerKH.LocalReport.DataSources.Clear();
                reportViewerKH.LocalReport.DataSources.Add(rds);

                List<ReportParameter> listBien2 = new List<ReportParameter>();
                ReportParameter bien2 = new ReportParameter("tungay2", dateTimePicker1.Value.ToString("dd/MM/yyyy"));
                listBien2.Add(bien2);
                ReportParameter bien4 = new ReportParameter("denngay2", dateTimePicker2.Value.ToString("dd/MM/yyyy"));
                listBien2.Add(bien4);
                reportViewerKH.LocalReport.SetParameters(listBien2);

                this.reportViewerKH.RefreshReport();
                reportViewerKH.Visible = true;
                reportViewer1.Visible = false;
                reportViewerNV.Visible = false;


            }
            else if (rbtnNV.Checked == true)
            {
                DateTime tungay1 = dateTimePicker1.Value;
                DateTime denngay1 = dateTimePicker2.Value;

                QLKD_KhoaLuanDataSet.NhanVienDataTable dt_NV = new QLKD_KhoaLuanDataSet.NhanVienDataTable();
                QLKD_KhoaLuanDataSetTableAdapters.NhanVienTableAdapter ada_NV = new KhoBanHang.QLKD_KhoaLuanDataSetTableAdapters.NhanVienTableAdapter();
                ada_NV.Fill(dt_NV, tungay1, denngay1);
                ReportDataSource rds = new ReportDataSource("QLKD_KhoaLuanDataSet_NhanVien", dt_NV);
                reportViewerNV.LocalReport.DataSources.Clear();
                reportViewerNV.LocalReport.DataSources.Add(rds);

                List<ReportParameter> listBien1 = new List<ReportParameter>();
                ReportParameter bien1 = new ReportParameter("tungay1", dateTimePicker1.Value.ToString("dd/MM/yyyy"));
                listBien1.Add(bien1);
                ReportParameter bien3 = new ReportParameter("denngay1", dateTimePicker2.Value.ToString("dd/MM/yyyy"));
                listBien1.Add(bien3);
                reportViewerNV.LocalReport.SetParameters(listBien1);

                this.reportViewerNV.RefreshReport();
                reportViewerNV.Visible = true;
                reportViewer1.Visible = false;
                reportViewerKH.Visible = false;

            }


        }
    }
}
